#include<bits/stdc++.h>
using namespace std;
int t,n,m,l,v,p[100000],p2[100000],qx=0,ert[100000],ans=0;
struct cp{
    int p1[10000],p3,p4;
}gbb[10000];
struct pc{
    int a,b,c;
}r[100000];
void mmz(double i,int j,int ij){
    bool q=0;
    for(int f=0;f<m;f++){
        if((p[f]<i&&p[f]>=ij&&j==0)||(p[f]>i&&j==1)){
            gbb[f].p1[qx]=1;q=1;
            p2[qx]++;gbb[f].p3++;
        }
    }
    if(q==1)qx++;
}
bool cmp(cp qwe,cp wer){
    if(qwe.p4!=wer.p4)return qwe.p4>wer.p4;
    return qwe.p3>wer.p3;
}

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int zg=0;zg<t;zg++){
        for(int i=0;i<qx;i++){
            for(int j=0;j<m;j++)gbb[j].p1[i]=0;
            p2[i]=0;
        }
        for(int j=0;j<m;j++)gbb[j].p3=0;
        qx=ans=0;
        cin>>n>>m>>l>>v;
        for(int i=0;i<n;i++){
            cin>>r[i].a>>r[i].b>>r[i].c;
        }
        for(int i=0;i<m;i++)cin>>p[i];
        for(int i=0;i<n;i++){
            double gb;
            if(r[i].c!=0)gb=r[i].a+(v*v-r[i].b*r[i].b)/(2.0*r[i].c);
            //cout<<gbb<<endl;
            if(r[i].c>=0&&r[i].b>v){
                mmz(r[i].a*1.0,1,0);
            }
            else {
                bool q=0;
                if(r[i].c>0&&r[i].b<v){
                    mmz(gb,1,0);
                }
                else if(r[i].c<0&&r[i].b>v){
                    mmz(gb,0,r[i].a);
                }
            }
        }
        cout<<qx<<' ';//<<endl;
        sort(gbb,gbb+m,cmp);
        for(int i=0;i<qx;i++)ert[i]=0;
        for(int i=0;i<m;i++){
                gbb[i].p4=0;
            for(int j=0;j<qx;j++){
                    //cout<<gbb[i].p1[j];
                if(gbb[i].p1[j]==1&&ert[j]==0){
                    gbb[i].p4+=1;
                }
            }
            //cout<<endl;
        }
        sort(gbb,gbb+m,cmp);
        for(int i=0;i<m;i++){
            bool rty=0;
            for(int j=0;j<qx;j++){
                    //cout<<gbb[i].p1[j];
                if(gbb[i].p1[j]==1&&ert[j]==0){
                    rty=1;
                    ert[j]=1;
                }
            }
            //cout<<endl;
            if(rty==0)ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}
